package com.x.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.x.common.bo.PageObject;
import com.x.common.exception.ServiceException;
import com.x.sys.dao.SysOrderDao;
import com.x.sys.entity.Order;
import com.x.sys.service.SysOrderService;

@Service
public class SysOrderServiceImpl implements SysOrderService {
	@Autowired
	private SysOrderDao sysOrderDao;
	
	@Override
	public PageObject<Order> findPageObjects(String number, Integer pageCurrent) 
			 throws ServiceException{
		if(pageCurrent==null||pageCurrent<1)
			throw new IllegalArgumentException("当前页码值不正确");
		
		int rowCount=sysOrderDao.getRowCount(number);
		if(rowCount==0)
			throw new ServiceException("没有对应记录");
		
		int pageSize=3;
		
		int startIndex=(pageCurrent-1)*pageSize;

		List<Order> records=
				sysOrderDao.findPageObjects(number, startIndex, pageSize);
		
		return new PageObject<>(records, rowCount, pageSize, pageCurrent);
	}

}
